<?php

/**
 * 
 * Gepard linker
 * All objects are loaded only on demand
 * @author taras
 *
 */
class gLinker 
{
	private $pool = array();
	
	function __construct()
	{
		
	}
	
	function __get($object)
	{
		if( array_key_exists($object, $this->pool))
		{
			return $this->pool[$object];
		}
		else
		{
			if( gCore::includeCoreObject($object) )
			{
				$classname = 'g'.ucfirst($object);
				$class = new $classname( $this );
				$class->init();
				$this->pool[$object] = $class;
				return $this->pool[$object];
			}
			else
			{
				throw new gException('Cannot load core object "'.$object.'"',gError::FILE_NOT_FOUND);
			}
		}
	}

    public function createObject($name)
    {
        $classname = 'g'.ucfirst($name);
        $this->$name = new $classname ( $this );
        $this->$name->init();
        $this->pool[$name] = $this->$name;
        return $this->pool[$name];
    }
    
    public function hasLoaded($objectname)
    {
    	return array_key_exists($objectname,$this->pool);
    }
    
}